<script setup lang="ts">
import useStore from "@/store";
import { storeToRefs } from "pinia";
const { main, footer, user } = useStore();
const { list, compeleted, unCompeleted } = storeToRefs(main);
const { id } = storeToRefs(user);
const { clearCompeleted } = main;
const { tabs, active, activeHash } = storeToRefs(footer);
const { getActive } = footer;
getActive();
</script>
<template>
	<footer class="footer" v-if="list.length > 0">
		<span class="todo-count">还剩<b>{{ unCompeleted.length }}</b>个任务</span>
		<ul class="filters">
			<li v-for="(item, index) in tabs" :key="index">
				<a :class="{ selected: item === active }" :href="`/todo/${activeHash[index]}`">
					{{ item }}
				</a>
			</li>
			<li v-if="compeleted.length > 0" @click="clearCompeleted(id)" class="clear-completed">清理所有已完成任务</li>
			<li v-else class="clear-completed" style="cursor:unset; text-decoration: none;">暂无完成任务</li>
		</ul>
	</footer>
</template>
<style scoped lang="scss">
.clear-completed {
	display: inline-block !important;
	margin-right: 5px !important;
	width: 135px !important;
}

.footer {
	padding: 10px 15px;
	height: 20px;
	text-align: center;
	font-size: 15px;
	border-top: 1px solid #e6e6e6;
}

.footer:before {
	content: '';
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	height: 50px;
	overflow: hidden;
	box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
		0 8px 0 -3px #f6f6f6,
		0 9px 1px -3px rgba(0, 0, 0, 0.2),
		0 16px 0 -6px #f6f6f6,
		0 17px 2px -6px rgba(0, 0, 0, 0.2);
}

.todo-count {
	float: left;
	text-align: left;
}

.todo-count strong {
	font-weight: 300;
}

.filters {
	margin: 0;
	padding: 0;
	list-style: none;
	position: absolute;
	right: 0;
	left: 0;
}

.filters li {
	display: inline;
}

.filters li a {
	color: inherit;
	margin: 3px;
	padding: 3px 7px;
	text-decoration: none;
	border: 1px solid transparent;
	border-radius: 3px;
}

.filters li a:hover {
	border-color: #DB7676;
}

.filters li a.selected {
	border-color: #CE4646;
}

.clear-completed,
html .clear-completed:active {
	float: right;
	position: relative;
	line-height: 19px;
	text-decoration: none;
	cursor: pointer;
}

.clear-completed:hover {
	text-decoration: underline;
}

@media (max-width: 430px) {
	.footer {
		height: 50px;
	}

	.filters {
		bottom: 10px;
	}
}
</style>
